package com.ocss.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ocss.common.annotation.Log;
import com.ocss.common.core.controller.BaseController;
import com.ocss.common.core.domain.AjaxResult;
import com.ocss.common.enums.BusinessType;
import com.ocss.system.domain.OcssSemester;
import com.ocss.system.service.IOcssSemesterService;
import com.ocss.common.utils.poi.ExcelUtil;
import com.ocss.common.core.page.TableDataInfo;

/**
 * 学期信息Controller
 *
 * @author ligen
 * @date 2024-03-05
 */
@RestController
@RequestMapping("/system/semester")
public class OcssSemesterController extends BaseController {
    @Autowired
    private IOcssSemesterService ocssSemesterService;

    /**
     * 查询学期信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:semester:list')")
    @GetMapping("/list")
    public AjaxResult list(OcssSemester ocssSemester) {
        List<OcssSemester> list = ocssSemesterService.selectOcssSemesterList(ocssSemester);
        return success(list);
    }

    /**
     * 导出学期信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:semester:export')")
    @Log(title = "学期信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OcssSemester ocssSemester) {
        List<OcssSemester> list = ocssSemesterService.selectOcssSemesterList(ocssSemester);
        ExcelUtil<OcssSemester> util = new ExcelUtil<OcssSemester>(OcssSemester.class);
        util.exportExcel(response, list, "学期信息数据");
    }

    /**
     * 获取学期信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:semester:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ocssSemesterService.selectOcssSemesterById(id));
    }

    /**
     * 新增学期信息
     */
    @PreAuthorize("@ss.hasPermi('system:semester:add')")
    @Log(title = "学期信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OcssSemester ocssSemester) {
        return toAjax(ocssSemesterService.insertOcssSemester(ocssSemester));
    }

    /**
     * 修改学期信息
     */
    @PreAuthorize("@ss.hasPermi('system:semester:edit')")
    @Log(title = "学期信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OcssSemester ocssSemester) {
        return toAjax(ocssSemesterService.updateOcssSemester(ocssSemester));
    }

    /**
     * 删除学期信息
     */
    @PreAuthorize("@ss.hasPermi('system:semester:remove')")
    @Log(title = "学期信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ocssSemesterService.deleteOcssSemesterByIds(ids));
    }
}
